package com.rtmart.imageupload.controller.supplier;

import com.rtmart.imageupload.entity.Supplier;
import com.rtmart.imageupload.repositoryImp.SupplierRepositoryImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.ArrayList;

@Controller
@RequestMapping("/supplier/")
public class SupplierUpdate {
    @Autowired
    private SupplierRepositoryImp supplierRepositoryImp;

    @GetMapping("update")
    public String getItemUpdate(Model model){
        model.addAttribute("supplierList", supplierRepositoryImp.supplierList());
        return "supplier/update";
    }
    @PostMapping("update")
    @Transactional
    public String postItemUpdate(Long[] id, String[] name, Integer[] state, RedirectAttributes redirectAttributes){
        supplierRepositoryImp.update(id, name, state);
        redirectAttributes.addFlashAttribute("message","保存成功！");
        return "redirect:/supplier/update";
    }
}
